-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Use FORWARDREF format in inspect.signature calls #13946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spam
Hmm, seems mypy does not like |
sphinx/util/inspect.py
Outdated
# Python 3.14 added the annotationlib module to the standard library as well as the | ||
# 'annotation_format' keyword parameter to inspect.signature(), which allows us to handle | ||
# forward references more robustly. | ||
try: | ||
import annotationlib # type: ignore[import-not-found] | ||
|
||
inspect_signature_extra = {'annotation_format': annotationlib.Format.FORWARDREF} | ||
except ImportError: | ||
inspect_signature_extra = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a module global, instead of being computed each time. Also, prefer using sys.version
checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved inspect_signature_extra
to the module scope and am now checking sys.version_info
instead of try/except ImportError
. Does this look acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test and CHANGES entry, and consider listing yourself in AUTHORS.
A
fb8ced5
to
e6d722c
Compare
I've now moved the Added forward reference tests to Using python 3.14, without the bug fix this new test ( Also fixed the lint issues, updated CHANGES, and added myself to AUTHORS. Hopefully everything looks good, happy to do further changes though, just let me know. |
Fixes #13945
Purpose
Python 3.14 adds the
annotationlib
module, as well as theannotation_format
keyword parameter toinspect.signature
.Passing
annotation_format=annotationlib.Format.FORWARDREF
toinspect.signature
calls allows us to support Python 3.14 forward references in annotations robustly, fixing the current issues described in #13945References
Fixes #13945